package com.ruoyi.employer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employer.domain.CargoConsignee;
import com.ruoyi.employer.service.ICargoConsigneeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收货人信息Controller
 * 
 * @author adf
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/employer/consignee")
public class CargoConsigneeController extends BaseController
{
    @Autowired
    private ICargoConsigneeService cargoConsigneeService;

    /**
     * 查询收货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:list')")
    @GetMapping("/list")
    public TableDataInfo list(CargoConsignee cargoConsignee)
    {
        startPage();
        List<CargoConsignee> list = cargoConsigneeService.selectCargoConsigneeList(cargoConsignee);
        return getDataTable(list);
    }

    /**
     * 查询所有收货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll()
    {
        List<CargoConsignee> list = cargoConsigneeService.selectCargoConsigneeList(null);
        return getDataTable(list);
    }

    /**
     * 导出收货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:export')")
    @Log(title = "收货人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CargoConsignee cargoConsignee)
    {
        List<CargoConsignee> list = cargoConsigneeService.selectCargoConsigneeList(cargoConsignee);
        ExcelUtil<CargoConsignee> util = new ExcelUtil<CargoConsignee>(CargoConsignee.class);
        util.exportExcel(response, list, "收货人信息数据");
    }

    /**
     * 获取收货人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        System.out.println("id:" + id);
        System.out.println("--------------------------------");
        System.out.println("cargoConsigneeService:" + cargoConsigneeService.selectCargoConsigneeById(id));
        return success(cargoConsigneeService.selectCargoConsigneeById(id));
    }

    /**
     * 新增收货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:add')")
    @Log(title = "收货人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CargoConsignee cargoConsignee)
    {
        return toAjax(cargoConsigneeService.insertCargoConsignee(cargoConsignee));
    }

    /**
     * 修改收货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:edit')")
    @Log(title = "收货人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CargoConsignee cargoConsignee)
    {
        return toAjax(cargoConsigneeService.updateCargoConsignee(cargoConsignee));
    }

    /**
     * 删除收货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consignee:remove')")
    @Log(title = "收货人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cargoConsigneeService.deleteCargoConsigneeByIds(ids));
    }
}
